package dongshi.daddy.huohuo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ChongRuLockMain {
    private static Lock lock = new ReentrantLock();
    public static void main(String[] args) {
        // 线程1先上锁，结束，但是不释放锁，即不unlock
        Thread t1 = new Thread(() -> ChongRuLockMain.m1(), "线程1号");
        t1.start();

        // 因为线程1没有unlock，所以线程2将被lockInterruptibly
        Thread t2 = new Thread(() -> ChongRuLockMain.m1(), "线程2号");
        t2.start();

        // 中断被lockInterruptibly方法阻塞的线程2
//         t2.interrupt();
    }

    private static void m1() {
//        try {
            boolean lockSuc = lock.tryLock();
        System.out.println(Thread.currentThread().getName() + " " + lockSuc);

//            lock.lock();
//        } catch (InterruptedException e) {
//            System.out.println(Thread.currentThread().getName() + " is interrupted!!!");
//        }
    }
}

